/*
 * @Author: wuqingchun
 * @Date: 2024-09-29 17:00:10
 * @Description: 
 * @LastEditors: wuqingchun
 * @LastEditTime: 2024-10-03 13:16:19
 */
#ifndef __CHAT_NET_H__
#define __CHAT_NET_H__


#include "../deps/muduo/muduo/net/TcpClient.h"
#include "../deps/muduo/muduo/net/EventLoop.h"
#include "../deps/muduo/muduo/net/EventLoopThread.h"
#include "../deps/muduo/muduo/net/InetAddress.h"


#include "chat_msg.h"

using namespace muduo;
using namespace muduo::net;


class CChatNet : public muduo::noncopyable
{
public:
    CChatNet(const char* pcServerHost, uint16_t usPort);
    ~CChatNet();

    int32_t Start();

    void setMessageCallback(const MessageCallback& refMsgCB);
    int32_t Send(CHAT_MSG_HEAD_S& refMsg);

private:
    void __OnThreadInit(EventLoop* pobjEVLoop);
    void __OnConnect(const TcpConnectionPtr& refConnPtr);
private:
    InetAddress m_objNetAddr;
    EventLoop   m_objEVLoop;
    EventLoopThread m_objThread;
    std::string m_strServerName;
    TcpClient   m_objTcpClient;
    TcpConnectionPtr m_pConn = nullptr;
};

#endif //__CHAT_NET_H__